package com.example.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.demo.common.R;
import com.example.demo.entity.pojo.Department;
import com.example.demo.service.DepartmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liye
 * @date 2025/10/9 14:31
 * @description:
 */
@RestController
@RequestMapping("/dept")
@Tag(name = "科室管理")
public class DepartmentController {

    @Resource
    private DepartmentService departmentService;

    // 获取所有科室列表
    @GetMapping("/list")
    @Operation(summary = "获取所有科室列表")
    public R list() {
        List<Department> list = departmentService.list();
        return R.success(list);
    }

    // 根据院区ID获取科室列表
    @GetMapping("/listByArea/{areaId}")
    @Operation(summary = "根据院区ID获取科室列表")
    public R listByArea(@PathVariable("areaId") Integer areaId) {
        LambdaQueryWrapper<Department> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Department::getAreaId, areaId);
        List<Department> list = departmentService.list(queryWrapper);
        return R.success(list);
    }
}
